<template>
	<view class="container">
		<!-- 导航栏 -->
		<view class="nav-bar">
			<view class="nav-left" @click="goBack">
				<image src="/static/icon/back.png" mode="aspectFit"></image>
			</view>
			<text class="nav-title">编辑用户信息</text>
			<view class="nav-right"></view>
		</view>
		
		<!-- 内容区域 -->
		<view class="content">
			<!-- 头像编辑区域 -->
			<view class="avatar-section">
				<text class="section-title">头像<text class="required">*</text></text>
				<view class="avatar-wrapper" @click="chooseAvatar">
					<image 
						:src="avatarUrl || '/static/icon/touxiang.png'" 
						mode="aspectFill" 
						class="avatar"
					></image>
				</view>
			</view>
			
			<!-- 昵称编辑区域 -->
			<view class="nickname-section">
				<text class="section-title">昵称<text class="required">*</text></text>
				<input 
					type="text" 
					v-model="nickname" 
					placeholder="请输入昵称" 
					class="nickname-input"
					maxlength="20"
				/>
			</view>
			
			<!-- 提交按钮 -->
			<button class="submit-btn" @click="submitInfo">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatarUrl: '',
				nickname: ''
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			chooseAvatar() {
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album', 'camera'],
					success: (res) => {
						this.avatarUrl = res.tempFilePaths[0]
					}
				})
			},
			submitInfo() {
				if (!this.avatarUrl) {
					uni.showToast({
						title: '请选择头像',
						icon: 'none'
					})
					return
				}
				if (!this.nickname.trim()) {
					uni.showToast({
						title: '请输入昵称',
						icon: 'none'
					})
					return
				}
				// TODO: 提交信息到服务器
				uni.showToast({
					title: '保存成功',
					icon: 'success',
					success: () => {
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.container {
	min-height: 100vh;
	background-color: #F8F8F8;
	
	.nav-bar {
		background-color: #FFFFFF;
		height: 88rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		position: relative;
		
		.nav-left {
			width: 60rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			
			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
		
		.nav-title {
			font-size: 32rpx;
			font-weight: 500;
			color: #333333;
		}
		
		.nav-right {
			width: 60rpx;
		}
	}
	
	.content {
		padding: 30rpx;
		
		.avatar-section, .nickname-section {
			background-color: #FFFFFF;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			
			.section-title {
				font-size: 30rpx;
				color: #333333;
				font-weight: 500;
				
				.required {
					color: #FF3B30;
					margin-left: 4rpx;
				}
			}
		}
		
		.avatar-wrapper {
			width: 120rpx;
			height: 120rpx;
			border-radius: 60rpx;
			overflow: hidden;
			background-color: #F5F5F5;
			
			.avatar {
				width: 100%;
				height: 100%;
			}
		}
		
		.nickname-section {
			.nickname-input {
				flex: 1;
				margin-left: 30rpx;
				height: 80rpx;
				font-size: 30rpx;
				text-align: right;
			}
		}
		
		.submit-btn {
			width: 100%;
			height: 88rpx;
			background: linear-gradient(to right, #3D9BEF, #00D0FF);
			color: #FFFFFF;
			font-size: 32rpx;
			font-weight: 500;
			border-radius: 44rpx;
			margin-top: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			
			&:active {
				opacity: 0.8;
			}
		}
	}
}
</style>
